<template>
  	<div class="left-menu">
		<el-menu
			class="el-menu-vertical-demo"
			:default-active="path"
			@open="handleOpen"
			@close="handleClose"
			router
		>
			<div v-for="(item,index) in navList" :key="index">
				<div v-for="(auth,n) in item.Authority" :key="n">
					<div v-if="auth == Authority">
						<div v-if="item.sub.length>0">
							<el-submenu :index="item.url">
								<template slot="title">
									<i :class="item.ico"></i>
									<span>{{item.title}}</span>
								</template>
								<div v-for="(nav,i) in item.sub" :key='i' :index="nav.url">
									<div v-for="(navauth,navau) in nav.Authority" :key="navau">
										<div v-if="navauth == Authority">
											<el-menu-item :index="nav.url">{{nav.title}}</el-menu-item>
										</div>
									</div>
								</div>
							</el-submenu>
						</div>
						<div v-else>
							<el-menu-item :index="item.url">
								<i :class="item.ico"></i>
								<span slot="title">{{item.title}}</span>
							</el-menu-item>
						</div>
					</div>
				</div>
			</div>
			<!-- <el-menu-item index="/userList">
				<i class="el-icon-s-marketing"></i>
				<span slot="title">普通用户列表</span>
			</el-menu-item>
			<el-menu-item index="/merchantList">
				<i class="el-icon-s-management"></i>
				<span slot="title">加盟商列表</span>
			</el-menu-item>
        	<el-submenu index="3">
				<template slot="title">
					<i class="el-icon-s-management"></i>
					<span>品牌商管理</span>
				</template>
				<el-menu-item index="/brandDealerList">品牌商列表</el-menu-item>
				<el-menu-item index="/brandDealerGoodsList">品牌商商品</el-menu-item>
				<el-menu-item index="3">品牌商身份审核</el-menu-item>
				<el-menu-item index="3">品牌商提现审核</el-menu-item>
        	</el-submenu>
			<el-menu-item index="/sellTotal">
				<i class="el-icon-s-marketing"></i>
				<span slot="title">销售统计</span>
			</el-menu-item>-->
        	
      	</el-menu>
  	</div>
</template>

<script>
  	export default {
		name: 'LeftMenu',
		data(){
			return{
				Authority:localStorage.getItem('Authority'),
				navList:[
					{
						title:'系统首页',
						url:'/',
						ico:'el-icon-s-home',
						Authority:[1,3],
						sub:[]
					},
					{
						title:'商品管理',
						url:'1',
						ico:'el-icon-s-shop',
						Authority:[1],
						sub:[{
								title:'商品列表',
								url:'/goodsList',
								Authority:[1]
							},{
								title:'商品分类',
								url:'/goodsTypeList',
								Authority:[1]
							}
						]
					},{
						title:'普通用户列表',
						url:'/userList',
						ico:'el-icon-s-marketing',
						sub:[],
						Authority:[1]
					},{
						title:'加盟商列表',
						url:'/merchantList',
						ico:'el-icon-s-management',
						sub:[],
						Authority:[1]
					},{
						title:'订单管理',
						url:'2',
						ico:'el-icon-s-order',
						Authority:[1,2,3],
						sub:[{
								title:'加盟商采购',
								url:'/merchantOrderList',
								Authority:[1,2,3]
							},{
								title:'加盟商退单',
								url:'/merchantReturnList',
								Authority:[1]
							},{
								title:'普通用户订单',
								url:'/orderList',
								Authority:[1,2,3]
							},{
								title:'普通用户退单',
								url:'/returnList',
								Authority:[1]
							}
						]
					},{
						title:'用户管理',
						url:'3',
						ico:'el-icon-s-custom',
						Authority:[1],
						sub:[{
								title:'系统用户',
								url:'/admin/user',
								Authority:[1]
							},{
								title:'操作日志',
								url:'/admin/log',
								Authority:[1]
							}
						]
					}
				]
			}
		},
    	computed: {
      		//  获取顶层路由
			path() {
				let path = this.$route.path
				const index = path.indexOf('/')
				const nextIndex = path.indexOf('/', index + 1)
				return nextIndex != -1 ? path.substring(0, nextIndex) : path
			}
    	},
		methods: {
			handleOpen(){},
			handleClose(){}
		}
  	}
</script>

<style lang="scss">
	.left-menu {
		width: 200px;
		border-right: solid 1px #e6e6e6;
		.el-menu{
			border-right: 0;
		}
	}
</style>
